package com.atguigu.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;


class MyThread implements Callable<Integer> {
    @Override
    public Integer call() throws Exception{
        System.out.println("-------come in call method");
        //暂停几秒钟线程
        try{
            TimeUnit.SECONDS.sleep(3);
        }catch(InterruptedException e){e.printStackTrace();}
        return 1229;
    }
}
public class CallableDemo {
    public static void main(String[] args)throws ExecutionException , InterruptedException{
        FutureTask futureTask = new FutureTask(new  MyThread());
        Thread t1=new Thread(futureTask,"t1");
        t1.start();
        System.out.println(futureTask.get());
         FutureTask futureTask2=new FutureTask(new  MyThread());
         Thread t2=new Thread(futureTask2,"t2");
         t2.start();

        System.out.println(Thread.currentThread().getName()+"\t"+futureTask2.get());
    }
}
